$(document).ready(function() {
	$('#menu_management_button').click(function () {
		if(window.name == 'menu_management')
			window.name = false;
		else
			window.name = 'menu_management';
		$('#menu_management').slideToggle('medium')
	});
	
	oppened_menu = document.getElementById(window.name);
	oppened_menu.style.display = 'block';
});

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
		thefield.value = ""
} 

function returnText(thefield){
	if (thefield.value == "")
		thefield.value = thefield.defaultValue
}

function hide_island_reserve(qde_island){
	var i;
	for(i = 0; i < qde_island; i++){
		var island;
		island = document.getElementById('reserve_island_div'+i);
		island.style.display = 'none';
	}
}

function reserve_on_island(qde_island,institution,id){
	var island_to_open;
	island_to_open = document.getElementById('reserve_island_div'+id);
	
	if(island_to_open.style.display == 'block')
		island_to_open.style.display = 'none';
	else{
		hide_island_reserve(qde_island);
		island_to_open.style.display = 'block';
	}
}

function alter_request_qde(island,msg){
	var aChk = document.getElementsByName("book_nodes_"+island+"[]");
	var aChk2 = document.getElementsByName("book_specs_"+island+"[]");
	var select2 = document.getElementById('institution_title_'+island);
	var qtd_marked = 0;
	
	for (var i=0;i<aChk.length;i++){ 
		if (aChk[i].checked == true)
			qtd_marked++;
	}
	
	for (var i=0;i<aChk2.length;i++){ 
		if (aChk2[i].checked == true)
			qtd_marked++;
	}
	
	if(qtd_marked == 0)
		select2.innerHTML = ""+msg+"";
	else
		select2.innerHTML = ""+msg+" ["+qtd_marked+"]";
}

function checkCheckbox(container, sender){
	var checktoggle = sender.checked;
	var checkboxes = new Array();
	checkboxes = document.getElementById(container).getElementsByTagName('input');
	
	for (var i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].type === 'checkbox') {
			checkboxes[i].checked = checktoggle;
		}
	}
}

function changeResourceType(field){
	var fieldsToChange = "." + field + "_fields";
	$('.node_fields').hide();
	$('.channel_fields').hide();
	$(fieldsToChange).show();
}

function showReservationDetails(reservationID) {
	var hidden = $('#reservation_details_' + reservationID).is(':hidden');
	
	$('.hidden_resources').hide();
	
	if( hidden )
		$('#reservation_details_' + reservationID).show();
}

function confirmRemove(text, form) {
	var remove = confirm(text);
	
	if(remove)
		form.form.submit();
}
